package com.education.online.controller;


import com.education.common.pojo.OResources;
import com.education.common.utils.ApiReturnObject;
import com.education.online.pojo.OCatalogLesson;
import com.education.online.service.OCatalogLessonService;
import com.education.online.service.OResourcesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 专业课程体系资源表
 *
 * @date 2020-06-04 15:17:55
 */
@Api(tags = {"PC--专业课程体系资源表"})
@RestController
@RequestMapping("/online/oresources")
public class OResourcesController {

    @Autowired
    private OResourcesService oResourcesService;

    @Autowired
    private OCatalogLessonService oCatalogLessonService;

    @ApiOperation(value = "查询全部课程", httpMethod = "GET")
    @GetMapping("/selectResourcesByCatalogIdAndType")
    public ApiReturnObject selectList(OResources oResources){
        //如果是虚拟教学 则切割开返回   8 虚拟教学 5 实操视频 4 实战照片 2 技术文档 5 章节测试 1 教学课件
        if (oResources.getType().equals("8")){
            List<OResources> resourcesList = oResourcesService.selectOResourcesList(oResources);
            for (OResources resources : resourcesList) {
                String[] split = resources.getRUrl().split(",");
                resources.setThreeD(split[0]);
                resources.setFalsh(split[1]);
            }
            return new ApiReturnObject("200","success",resourcesList.size(),resourcesList);
        }

        List<OResources> resourcesList = oResourcesService.selectOResourcesList(oResources);
        for (OResources resources : resourcesList) {
            if (resources.getRCatalogid() != null){
                OCatalogLesson oCatalogLesson = oCatalogLessonService.selectOCatalogLessonById(resources.getRCatalogid());
                resources.setRRemark("所属章节 : " + oCatalogLesson.getCatalogName());
            }else {
                resources.setRRemark("所属章节 : 公共");
            }
        }
        return new ApiReturnObject("200","success",resourcesList.size(),resourcesList);
    }

    /**
     * feign : 根据id和类型查询资源数据
     */
    @GetMapping("/selectResources")
    public List<OResources> selectResources(Integer[] ids, Integer type) {
        List<OResources> resourcesList = oResourcesService.selectOResourcesByIdsAndType(ids, type);
        return resourcesList;
    }
}
